package cn.tedu.csmall.product.web;

import cn.tedu.csmall.product.exception.ServiceException;
import cn.tedu.csmall.product.pojo.vo.AlbumListItemVO;
import lombok.Data;

import java.util.List;

@Data
public class JsonResult {
    private Integer code;
    private String message;
    private Integer result;
    private List<?> data;

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public static JsonResult ok(List<?> data) {
        JsonResult jr = new JsonResult();
        jr.code = ServiceCode.OK;
        jr.data = data;
        return jr;
    }

    public static JsonResult ok() {
        JsonResult jr = new JsonResult();
        jr.code = ServiceCode.OK;
        return jr;
    }
    public static JsonResult ok(Integer result) {
        JsonResult jr = new JsonResult();
        jr.code = ServiceCode.OK;
        jr.result = result;
        return jr;
    }

    public static JsonResult fail(ServiceException e){
        JsonResult jr = new JsonResult();
        return fail(jr.getCode(),jr.getMessage());
    }

    public static JsonResult fail(Throwable e){
        JsonResult jr = new JsonResult();
        return fail(jr.getCode(),jr.getMessage());
    }

    public static JsonResult fail(Integer code,String message){
        JsonResult jr = new JsonResult();
        jr.code = code;
        jr.message = message;
        return jr;
    }
}
